package cn.com.web.Servlet;

import cn.com.service.CustomerService;
import cn.com.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteCustomerServlet")
public class DeleteCustomerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取所有id
        String[] cuids = request.getParameterValues("cuid");
        //2.调用service删除
        CustomerService service=new CustomerServiceImpl();
        if (  cuids==null || cuids.length<1){
            String cuidd=request.getParameter("cuid");
            service.delteCustomerbyid(cuidd);
        }else for (String cuid : cuids) {
            service.delteCustomerbyid(cuid);
        }
        //请求转发到ShowCustomerServlet
        request.getRequestDispatcher("FindCustomerByPageServlet?currentPage=1&rows=5").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
